package nc;
import java.util.*;
import org.junit.*;

public class Shapee {
    
    public int[] GetEndPoint (String order) {
        char[] cs = order.toCharArray();
        int[] point = {0, 0};
        Map<Character, int[]> map = new HashMap<Character, int[]>(){{
            put('W', new int[]{1, 0});
            put('A', new int[]{0, -1});
            put('S', new int[]{-1, 0});
            put('D', new int[]{0, 1});
            put('w', new int[]{1, 0});
            put('a', new int[]{0, -1});
            put('s', new int[]{-1, 0});
            put('d', new int[]{0, 1});
        }};
        int n = cs.length;
        int last = 1;
        for (int i = 0; i < n; i++) {
            if (cs[i] >= '0' && cs[i] <= '9') {
                int j = i, res = 0;
                while (cs[j] >= '0' && cs[j] <= '9') {
                    res = res * 10 + (cs[j] - '0');
                    j++;
                }
                last = res;
                i = j - 1;
            } else {
                int[] next = map.get(cs[i]);
                point[0] += next[0] * last;
                point[1] += next[1] * last;
                //防止没有last的情况。
                last = 1;
            }

        }
        return point;
    }

    

    @Test
    public void test() {
        System.out.println(GetEndPoint("1000a1000d1000w900s"));
    }

    public String compressString (String param) {
        param += '#';
        char[] cs = param.toCharArray();
        int n = cs.length;
        StringBuilder sb = new StringBuilder();

        char last = cs[0];
        int lastTimes = 1;

        for (int i = 1; i < n; i++) {
            if (cs[i] == last) {
                lastTimes++;
            } else {
                if (lastTimes > 1) {
                    sb.append(last);
                    sb.append(lastTimes);
                }
                last = cs[i];
                lastTimes = 1;
            }
        }

        return sb.toString();
    }

}
